package articles.craw.controller;

import java.io.IOException;
import java.util.Date;
import java.util.List;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import articles.data.QnAPersistenceManager;
import articles.model.LinkCraw;

@SuppressWarnings("serial")
public class UpdateLinkCrawServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		resp.setContentType("text/plain");
		
		PersistenceManager psm = QnAPersistenceManager.get().getPersistenceManager();
		
		Query query = psm.newQuery(LinkCraw.class);
		query.setFilter("domain == 'xooarticles.com'");
		@SuppressWarnings("unchecked")
		List<LinkCraw> listLink = (List<LinkCraw>) query.execute();
		if(listLink.size() > 0)
		{
			LinkCraw link;
			for(int i=0;i<listLink.size();i++)
			{
				link = listLink.get(i);
				link.setActive("1");
				psm=JDOHelper.getPersistenceManager(link);
				psm.currentTransaction().begin();
				psm.makePersistent(link);
				psm.currentTransaction().commit();
			}
		}
		Query query1 = psm.newQuery(LinkCraw.class);
		query1.setFilter("domain == 'xooarticles.com'");
		@SuppressWarnings("unchecked")
		List<LinkCraw> listLink1 = (List<LinkCraw>) query.execute();
		if(listLink1.size() > 0)
		{
			LinkCraw link;
			for(int i=0;i<listLink1.size();i++)
			{
				link = listLink.get(i);
				link.setActive("1");
				psm=JDOHelper.getPersistenceManager(link);
				psm.currentTransaction().begin();
				psm.makePersistent(link);
				psm.currentTransaction().commit();
			}
		}
	}
}
